package com.actor.testapplication;

import android.os.Bundle;
import android.view.ViewGroup;

import com.actor.myandroidframework.utils.toaster.ToasterUtils;
import com.actor.testapplication.activity.BaseActivity;
import com.actor.testapplication.databinding.ActivityZoomLayoutBinding;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;

/**
 * description: View缩放
 * company    :
 * @author    : ldf
 * date       : 2024/6/20 on 17:27
 */
public class ZoomLayoutActivity extends BaseActivity<ActivityZoomLayoutBinding> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("View缩放");

        viewBinding.btn1.setOnClickListener(v -> {
            ToasterUtils.success("btn1");
        });
        viewBinding.btn2.setOnClickListener(v -> {
            ToasterUtils.success("btn2");
        });

        /**
         * 需要代码设置内容宽高
         * 注意:
         *   如果 {@link viewBinding.iv}设置{@link R.drawable.island_home}够宽,
         *   那么 {@link viewBinding.zoomLayout}就可以不设置高度, {@link viewBinding.clContent}就可以不设置宽高,
         *   就可以不用下方代码设置宽度!!!
         */
        ViewGroup.LayoutParams lp = viewBinding.clContent.getLayoutParams();
        lp.width = ScreenUtils.getAppScreenWidth() - 250;
        lp.height = SizeUtils.dp2px(252);
        viewBinding.clContent.setLayoutParams(lp);

        //ZoomLayout 包裹的高度, 也设置同样高度
        ViewGroup.LayoutParams lp2 = viewBinding.zoomLayout.getLayoutParams();
        lp2.height = lp.height + 300;
        viewBinding.zoomLayout.setLayoutParams(lp2);

        /**
         * How to zoom to 1 but have it zoom to the center? #231
         * https://github.com/natario1/ZoomLayout/issues/231
         * 将子View移动到中心 (只要ContentView位于ZoomLayout的左上角, 就会自动移动到中心!!)
         */
//        viewBinding.zoomLayout.moveTo(1f, 0f, 0f, true);
    }

    private Long lastClickTime = 0L;
    private Boolean isFastDoubleClick(){
        Long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }
}